<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText" @tap="onreturn()">返回</block>
			<block slot="content">库存预警</block>
		</cu-custom>
         
		<scroll-view scroll-x class="bg-white nav text-center fixed" :style="[{top:CustomBar + 'px'}]">
			<view class="cu-item" :class="index==TabCur?'text-blue cur':''" v-for="(item,index) in devtypelist"
				:key="index" @tap="tabSelect" :data-id="index">
				<block>
					<text :class="devtypelist[index].icon" type="default"></text>
					<text style="padding-left: 5px;" type="default">
						{{devtypelist[index].title}}</text>
				</block>

			</view>

		</scroll-view>
		<scroll-view scroll-y :style="[{top:CustomBar+300 + 'px'}]">

			<view class="cu-list menu-avatar" style="margin-top: 100upx;">
				<block v-if="TabCur==0">
					<view class="cu-item" style="height: 220upx;margin-bottom: 20upx;;"
						v-for="(item,i) in listcontents_before" :key="i">

						<view class="content" style="left: 30upx;">
							<template> 
								<view>
									<view class="text-grey">商品名称:&emsp;{{item.name}}</view>
								</view>
								<view>
									<view class="text-grey">规格:&emsp;{{item.guige}}</view>
								</view>
								<view>
									<view class="text-grey">库存:&emsp;
									<text class="text-red " style="padding-left: 20px;">
										&emsp;{{item.num}}
									</text>
									</view>
								</view>

							</template>
						</view>
					 
					</view>
				</block>

				<block v-if="TabCur==1">
					<view class="cu-item" style="height: 220upx;margin-bottom: 20upx;"
						v-for="(item,i) in listcontents_after" :key="i">
						<view class="content" style="left: 30upx;">
							<template>
							<!-- 	<view>
									<view class="text-grey">商品ID:{{item._id}}</view>
								</view> -->
								<view>
									<view class="text-grey">商品名称:&emsp;{{item.name}}</view>
								</view>
								<view>
									<view class="text-grey">规格:&emsp;{{item.guige}}</view>
								</view>
								<view>
									<view class="text-grey">库存:&emsp;
									<text class="text-red " style="margin-left: 10px;font-weight: bold;">
										{{item.num}}
									</text>
									</view>
								</view>
							</template>
						</view>
						 
					</view>
				</block>
				 
			</view>

		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				CustomBar: this.CustomBar,
				maxnum:10,
				TabCur: 0,
				pid: 0,
				username: '',
				listcontents_before: [],
				listcontents_after: [],
				devtypelist: [{
						title: '商品',
						icon: 'cuIcon-goods'
					},
					{
						title: '物资',
						icon: 'cuIcon-roundcheck'
					},
				],
			}
		},
		onShow() {
			this.getorderlist();
		},
		onLoad(event) {
			this.pid = event.pid;
			console.log('当前选项卡' + this.pid);
			this.TabCur = this.pid;
		},
		onBackPress(options) {
			// Android 实体返回键 (from = backbutton)
			// 顶部导航栏左边的返回按钮 (from = backbutton)
			// 返回 API，即 uni.navigateBack() (from = navigateBack)

			if (options.from === 'navigateBack') {
				return false;
			}
			this.backButton();
			return true;

		},

		methods: {
			// 全文展开收起
			toggleDescription(num) {
				//this.showText = !this.showText;
				uni.showModal({
					content: num
				})
			},
			toLogin() {
				uni.navigateTo({
					url: '../login/login'
				})
			},
			// 返回上一页
			onreturn() {
				uni.reLaunch({
					url: '../index/index'
				});
			},
			backButton() {
				uni.navigateBack({
					delta: 1
				});
			},
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60;

				console.log('当前选项卡' + this.TabCur);

			},
			todetail() {
				uni.navigateTo({
					url: 'orderdetail'
				})
			},
			toPage(url) {
				if (!url) {
					uni.showToast({
						title: '模板未包含此页面',
						icon: "none"
					});
					return;
				}
				uni.navigateTo({
					url: url
				})
			},
			onPullDownRefresh() {
				//监听下拉刷新动作的执行方法，每次手动下拉刷新都会执行一次
				this.getorderlist();
				console.log('refresh');
				setTimeout(function() {
					uni.stopPullDownRefresh(); //停止下拉刷新动画
				}, 1000);
			},
 
			getorderlist() {
				//商品集合
				var _self = this;
				uniCloud.callFunction({
					name: "goodalarm",
					data: {
						typeid: 'shangpin',
						maxnum:_self.maxnum   //小于 数量预警
					}
				}).then((res) => {
					const {
						result
					} = res
					_self.listcontents_before = result.data
				});

				uniCloud.callFunction({
					name: "goodalarm",
					data: {
						typeid: 'wuzi',
						maxnum:_self.maxnum  //小于 数量预警
					}
				}).then((res) => {
					const {
						result
					} = res
					_self.listcontents_after = result.data
				})

			},
			 

		}
	}
</script>

<style>
	.bottom-box {
		position: fixed;
		width: 100%;
		bottom: 0;
		font-size: 28upx;
		color: #000000;
		border-top: 1upx solid #eee;
		height: 100upx;
		line-height: 100upx;
		//background: #fff url() no-repeat 705upx center;
		background-color: #FFFFFF;
		background-size: 15upx auto;
	}

	.bottom-box .add-btn {
		margin-left: 30upx;
		padding-left: 70upx;
		background: url() no-repeat left center;
		background-size: 40upx auto;
	}
</style>
